#include "StdAfx.h"
#include "Lord.h"
#include "UIHistory.h"

CUIHistory::CUIHistory(void)
{
}

CUIHistory::~CUIHistory(void)
{
}

void CUIHistory::Render(CDC *pDC)
{
	CRect rcBound = GetBound();
	g_imgHistoryBk.Draw(pDC->m_hDC, rcBound.left, rcBound.top);

	int nOffset = rcBound.Width() / Player_Count;
	int nCardWidth = g_imgCard.GetWidth() / CardImage_Col_Count;
	CObjPtrList<CPlayAction> &listHistory =  g_pLordGame->m_listHistory;
	int nCount = listHistory.GetCount();
	int arrSeatHandCount[Player_Count] = {0};
    for(int i = 0; i < nCount; i++)
	{
		CPlayAction *pPlayAction = listHistory[i];
		if(pPlayAction == NULL) 
			continue;
		if(pPlayAction->nAction != Play_ActionType_HeadOutCard && pPlayAction->nAction != Play_ActionType_OutCard)
			continue;
		int nSeat = pPlayAction->nSeat;
		int nSide = g_pLordGame->SeatToSide(nSeat);
		int nLeft = nOffset * nSide + (nOffset - nCardWidth) / 2;
		int nTop = arrSeatHandCount[nSeat] * 15;
		CRect rc(nLeft, nTop, nLeft + SmallCard_Width, nTop + SmallCard_Height);
		RenderPlayAction(pDC, pPlayAction, rc);
		arrSeatHandCount[nSeat]++;
	}
}

void CUIHistory::RenderPlayAction(CDC *pDC, CPlayAction *pPlayAction, CRect rc)
{
    int nCount = pPlayAction->m_listOutCard.GetCount();
	for(int i = 0; i < nCount; i++)
	{
		CCard &card = pPlayAction->m_listOutCard[i];
		card.RenderSmall(pDC);
	}
}

